Skip to content
Permalink
Browse files
startup: fix syslog calls to log the right error message
Summary:
Some calls to syslog with %m logged the wrong error in case a call
to write (2) failed just before. It made understanding errors tricky. With this fix,
some calls to syslog are re-ordered to log the right error message.

Test Plan: Run Cassandane tests.

Reviewers: #imap_reviewers

Differential Revision: https://git.cyrus.foundation/D46
  • Loading branch information
conradkleinespel authored and brong committed Aug 10, 2015
1 parent ccbc244 commit a2a5faa4fef36141c14b6cac9fe6260467761d8c
Showing 1 changed file with 23 additions and 8 deletions.
@@ -2198,7 +2198,9 @@ int main(int argc, char **argv)
int exit_result = EX_OSERR;

/* Tell our parent that we failed. */
r = write(startup_pipe[1], &exit_result, sizeof(exit_result));
if (write(startup_pipe[1], &exit_result, sizeof(exit_result)) == -1) {
syslog(LOG_ERR, "can't write to startup parent pipe: %m");
}

fatal("setsid failure", EX_OSERR);
}
@@ -2211,10 +2213,13 @@ int main(int argc, char **argv)
if(pidfd == -1) {
int exit_result = EX_OSERR;

syslog(LOG_ERR, "can't open pidfile: %m");

/* Tell our parent that we failed. */
r = write(startup_pipe[1], &exit_result, sizeof(exit_result));
if (daemon_mode && write(startup_pipe[1], &exit_result, sizeof(exit_result)) == -1) {
syslog(LOG_ERR, "can't write to startup parent pipe: %m");
}

syslog(LOG_ERR, "can't open pidfile: %m");
exit(EX_OSERR);
} else {
char buf[100];
@@ -2223,7 +2228,9 @@ int main(int argc, char **argv)
int exit_result = EX_OSERR;

/* Tell our parent that we failed. */
r = write(startup_pipe[1], &exit_result, sizeof(exit_result));
if (write(startup_pipe[1], &exit_result, sizeof(exit_result)) == -1) {
syslog(LOG_ERR, "can't write to startup parent pipe: %m");
}

fatal("cannot get exclusive lock on pidfile (is another master still running?)", EX_OSERR);
} else {
@@ -2234,10 +2241,14 @@ int main(int argc, char **argv)
if (pidfd_flags == -1) {
int exit_result = EX_OSERR;

syslog(LOG_ERR, "unable to set close-on-exec for pidfile: %m");

/* Tell our parent that we failed. */
r = write(startup_pipe[1], &exit_result, sizeof(exit_result));
if (write(startup_pipe[1], &exit_result, sizeof(exit_result)) == -1) {
syslog(LOG_ERR, "can't write to startup parent pipe: %m");
}

fatalf(EX_OSERR, "unable to set close-on-exec for pidfile: %m");
fatalf(EX_OSERR, "unable to set close-on-exec for pidfile (see syslog for details)");
}

/* Write PID */
@@ -2247,10 +2258,14 @@ int main(int argc, char **argv)
write(pidfd, buf, strlen(buf)) == -1) {
int exit_result = EX_OSERR;

syslog(LOG_ERR, "unable to write to pidfile: %m");

/* Tell our parent that we failed. */
r = write(startup_pipe[1], &exit_result, sizeof(exit_result));
if (daemon_mode && write(startup_pipe[1], &exit_result, sizeof(exit_result)) == -1) {
syslog(LOG_ERR, "can't write to startup parent pipe: %m");
}

fatalf(EX_OSERR, "unable to write to pidfile: %m");
fatalf(EX_OSERR, "unable to write to pidfile (see syslog for details)");
}
if (fsync(pidfd))
fatalf(EX_OSERR, "unable to sync pidfile: %m");

0 comments on commit a2a5faa

Please sign in to comment.